﻿'use strict';
import ServicesConfig from '../services/config.js'

export default {
		requestimeout(ms, promise) 
		{
				return new Promise(function(resolve, reject) {
				setTimeout(function() {
					reject(new Error('请求超时，请重新尝试'))
				}, ms)
				promise.then(resolve, reject)
				})
		},
		requestPost(action,formData)
		{
			 	var url = ServicesConfig.OSCServiceUrl+'/'+action;
				return fetch(url, 
						{
							credential:'include',//带上cookie发送请求请求
							method: 'POST',
							headers: {
								'Content-Type': 'multipart/form-data',
							},
							body: formData
						});
		},
		requestGet(action,paras)
		{
				if(!paras)
						paras='';
			 	var url = ServicesConfig.OSCServiceUrl+'/'+action+(paras===''?'':'?'+paras);
				return fetch(url, 
						{
							credential:'include',//带上cookie发送请求请求
							method: 'GET'
						});
		}
};